<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="反馈遇见的问题" prop="topupFeedbackIssue">
        <el-select v-model="queryParams.topupFeedbackIssue" placeholder="请选择" clearable size="small">
          <el-option label="请选择" value="" />
          <el-option label="自助充值" value="1" />
          <el-option label="客服充值" value="2" />



        </el-select>
      </el-form-item>
      <el-form-item label="订单号" prop="topupFeedbackOrder">
        <el-input
          v-model="queryParams.topupFeedbackOrder"
          placeholder="请输入订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="反馈时间" prop="topupFeedbackTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.topupFeedbackTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择反馈时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="是否阅读" prop="topupFeedbackWatch">
        <el-input
          v-model="queryParams.topupFeedbackWatch"
          placeholder="请输入是否阅读"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['xqsp:topupfeedback:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['xqsp:topupfeedback:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['xqsp:topupfeedback:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['xqsp:topupfeedback:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="topupfeedbackList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label=" 编号" align="center" prop="topupFeedbackId" />
      <el-table-column label="反馈遇见的问题" align="center" prop="topupFeedbackIssue" />
      <el-table-column label="订单号" align="center" prop="topupFeedbackOrder" />
      <el-table-column label="反馈描述" align="center" :show-overflow-tooltip="true" prop="topupFeedbackContent" />
      <el-table-column label="充值截图" align="center" prop="topupFeedbackImg">
        <template slot-scope="scope">
          <el-image :src="scope.row.topupFeedbackImg"  :preview-src-list="[scope.row.topupFeedbackImg]" style="width: 100px;height: 100px"/>
        </template>
      </el-table-column>
      <el-table-column label="反馈时间" align="center" prop="topupFeedbackTime" sortable width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.topupFeedbackTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否阅读" align="center" prop="topupFeedbackWatch" width="150">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.topupFeedbackWatch"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-text="已读"
            inactive-text="未读"
            :active-value=1
            :inactive-value=0
            @change="handleStatusChange(scope.row)">

          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['xqsp:topupfeedback:edit']"-->
<!--          >修改</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['xqsp:topupfeedback:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改充值反馈对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="订单号" prop="topupFeedbackOrder">
          <el-input v-model="form.topupFeedbackOrder" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="反馈描述">
          <el-input type="textarea" autosize v-model="form.topupFeedbackContent" />
        </el-form-item>
        <el-form-item label="充值截图" prop="topupFeedbackImg">
          <el-input v-model="form.topupFeedbackImg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="反馈时间" prop="topupFeedbackTime">
          <el-date-picker clearable size="small"
            v-model="form.topupFeedbackTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择反馈时间">
          </el-date-picker>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTopupfeedback, getTopupfeedback, delTopupfeedback, addTopupfeedback, updateTopupfeedback, exportTopupfeedback,changeUserStatus } from "@/api/xqsp/topupfeedback";
import Editor from '@/components/Editor';

export default {
  name: "Topupfeedback",
  components: {
    Editor,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 充值反馈表格数据
      topupfeedbackList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        topupFeedbackIssue: null,
        topupFeedbackOrder: null,
        topupFeedbackContent: null,
        topupFeedbackImg: null,
        topupFeedbackTime: null,
        topupFeedbackWatch: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询充值反馈列表 */
    getList() {
      this.loading = true;
      listTopupfeedback(this.queryParams).then(response => {
        this.topupfeedbackList = response.rows;
          this.topupfeedbackList.forEach(item=>{
            if (item.topupFeedbackIssue==1){
              item.topupFeedbackIssue="自主充值"
            }else if (item.topupFeedbackIssue==2){
              item.topupFeedbackIssue="客服充值"
            }
          });
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        topupFeedbackId: null,
        topupFeedbackIssue: null,
        topupFeedbackOrder: null,
        topupFeedbackContent: null,
        topupFeedbackImg: null,
        topupFeedbackTime: null,
        topupFeedbackWatch: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.topupFeedbackId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加充值反馈";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const topupFeedbackId = row.topupFeedbackId || this.ids
      getTopupfeedback(topupFeedbackId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改充值反馈";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.topupFeedbackId != null) {
            updateTopupfeedback(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTopupfeedback(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const topupFeedbackIds = row.topupFeedbackId || this.ids;
      this.$confirm('是否确认删除充值反馈编号为"' + topupFeedbackIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delTopupfeedback(topupFeedbackIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有充值反馈数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportTopupfeedback(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    },
    // 是否阅读
    handleStatusChange(row) {
      let text = row.topupFeedbackWatch === 0 ? "取消查看" : "查看";
      this.$confirm('确认要"' + text + '""' + row.topupFeedbackOrder + '"的意见反馈吗?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return changeUserStatus(row.topupFeedbackId, row.topupFeedbackWatch);
      }).then(() => {
        this.msgSuccess(text + "成功");
      }).catch(function() {
        row.topupFeedbackWatch = row.topupFeedbackWatch === 0 ? 1 : 0;
      });
    },
  }
};
</script>
<style ang="scss">
  .el-tooltip__popper{
    max-width: 300px;
    font-size: 16px;
    background: #000 !important;/*背景色  !important优先级*/
    opacity: 0.8 !important;/*背景色透明度*/
    color: #FFFFFF !important;/*字体颜色*/
  }
</style>
